package routers

import (
	"Myshop/controllers"
	beelog "github.com/astaxie/beego/logs"

	//beego "github.com/beego/beego/v2/server/web"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
	//beelog "github.com/astaxie/beego/logs"
)

func init() {
	beego.InsertFilter("/user/*", beego.BeforeExec, filterFunc)
	beego.Router("/register", &controllers.UserCon{}, "get:ShowRegister;post:PostRegister")
	beego.Router("/active", &controllers.UserCon{}, "get:ActiveMail")
	beego.Router("/login", &controllers.UserCon{}, "get:GetLogin;post:PostLogin")
	beego.Router("/user/home", &controllers.GoodsCon{}, "get:ShowHome")
	beego.Router("/user/userCenterInfo", &controllers.UserCon{}, "get:GetInfo")
	beego.Router("/user/userCenterOrder", &controllers.UserCon{}, "get:GetOrder")
	beego.Router("/user/userCenterSite", &controllers.UserCon{}, "get:GetSite;post:PostSite")
	beego.Router("/user/logout", &controllers.UserCon{}, "get:LogOut")
	//商品详情页
	beego.Router("/goodsDetail", &controllers.GoodsCon{}, "get:ShowGoodsDetail")
	//商品列表
	beego.Router("/goodsList", &controllers.GoodsCon{}, "get:ShowList")
	//商品搜索
	beego.Router("/goodsSearch", &controllers.GoodsCon{}, "post:HandelSearch")
	//	Ajax实现局部刷新购物车
	beego.Router("/user/addCart", &controllers.CartController{}, "post:HandleAddCart")
	//显示购物车页面
	beego.Router("/user/myCart", &controllers.CartController{}, "get:ShowCart")
	//更新购物车数据
	beego.Router("/user/updateCart", &controllers.CartController{}, "post:UpdateCart")
	//	删除购物车数据
	beego.Router("/user/deleteCart", &controllers.CartController{}, "post:DeleteCart")
	//展示订单页码
	beego.Router("/user/showOrder", &controllers.OrderController{}, "post:ShowOrder")
	//添加订单Ajax
	beego.Router("/user/addOrder", &controllers.OrderController{}, "post:AddOrder")
}

var filterFunc = func(ctx *context.Context) {
	name := ctx.Input.Session("userName")
	if name == "" {
		ctx.Redirect(302, "/login")
		beelog.Info("过滤成功，Session！")

		return
	}
}
